<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">

<head>
    <title>登陆</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="stylesheet" href="/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/bootstrap-responsive.min.css" />
    <link rel="stylesheet" href="/css/matrix-login.css" />
    <link rel="stylesheet" href="/css/demo.css">
    <link rel="stylesheet" href="/css/btn.css">




</head>
<body class="bg-blue">
<div style="width:100%;text-align: center;margin: 0 auto;position: absolute;">

    <!-- 登录 -->
    <div id="windows2" >
        <div id="loginbox">
            <form action="/checkPass" method="post" name="loginForm" id="loginForm" style="height: 340px">
                <div class="control-group normal_text">
                    <h3>
                        登录
                    </h3>

                </div>




                <div class="control-group">
                    <div class="controls">
                        <div class="main_input_box">
                            <span class="add-on bg_bb" >
                            <i>用户</i>
                            </span><input type="text" name="eid" id="eid"  placeholder="请输入工号" onblur="checkName()" />
                        </div>
                    </div>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <div class="main_input_box">
                            <span class="add-on bg_bb">
                            <i>密码</i>
                            </span><input type="password" name="mpwd" id = "password" placeholder="请输入密码" class="keypad" keypadMode="full" allowKeyboard="true" value=""/>
                        </div>
                    </div>
                </div>

                <div class="control-group " style="margin-left: 50px;">


                    <div class="bg_dg wid pull-left">
                        <input type="radio" name="identity"  id = "financial" value="financial" />
                        <label for="financial">管理</label>
                    </div>
                    <div class="bg_ly wid pull-left">
                        <input type="radio" name="identity" id = "manger" value="manger" />
                        <label for="manger">经理</label>
                    </div>
                    <div class="bg_lh wid pull-left" >
                        <input type="radio" name="identity" id = "employee" value="employee" />
                        <label for="employee">员工</label>
                    </div>
                    <select class="pull-left" id = "selection" style="visibility: hidden">
                        <option value="general">总经理</option>
                        <option value="deputy">副总经理</option>
                        <option value="divid">部门经理</option>
                    </select>

                </div>

                <div class="form-actions">
                    <div style="width:86%;padding-left:8%;">

                        <span class="pull-right">
                            <!--<input  class="btn btn-info"  value="登录" onlick="passempty()">-->
                            <button type="button" id="regBtn" class="btn btn-info" onclick="checkPass()">登录</button>
                        </span> </div>
                </div>
            </form>

        </div>
    </div>

</div>



<script src="/js/jquery-1.7.2.js"></script>
<script src="/js/jquery.easing.1.3.js"></script>
<script src="/js/jquery.mobile.customized.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/jQuery.md5.js"></script>
<script type="text/javascript" src="/js/jquery.tips.js"></script>
<script type="text/javascript" src="/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/layer/layer.js"></script>
<script>

        $('input[type=radio][name=identity]').change(function () {
            var identitylist = document.getElementsByName("identity");
            if(identitylist[1].checked && identitylist[1].value == "manger"){
                console.info("checked")
                document.getElementById("selection").style.visibility="visible"

            }else{
                console.info("here")
                document.getElementById("selection").style.visibility="hidden"
            }
        });

    function passempty() {
        var password = $("#password").val()
        if(password == ""  ){
            layer.msg("密码不能为空",{icon:5,time:1000})
            window.location="/login"
        }
        return true
    }
    function checkName() {

        var username = $("#eid").val()

        if(username == ""  ){
            layer.msg("工号不能为空")
            return false;
        }
        return true

    }
    function regist() {
        window.location="#"
    }
    function checkPass(){
        var eid = $("#eid").val()
        var pass = $("#password").val()
        var identitylist = document.getElementsByName("identity");
        var realidentity = document.getElementById("selection").value;

        var identity = null
        for(var i = 0; i < identitylist.length ; i++){
            if(identitylist[i].checked){
                identity = identitylist[i].value
            }
        }
        $.ajax({
                type: "post",
                url: "/check",
                data:{"eid":eid,
                "mpwd":pass},
                dataType:"json",
                success:function (result) {
                    if(result.data === true){
                        layer.msg("登录成功，即将跳转",{icon:1,time:500},function () {
                            console.info(identity)
                            if(identity == "employee") {
                                window.location="/cal"
                            }else if(identity == "manger"){
                                var redirect = "/"+realidentity+"/agreeleave"
                                console.info(redirect)
                                window.location = redirect
                            }else if(identity == "financial"){
                                window.location = "/financial"
                            }else{
                                window.location = "/"
                            }

                        })

                    }else{
                        layer.msg("登录失败",{icon:0,time:2000},function () {
                            window.location="/login"
                        })

                    }

                }
            }
        )
    }
</script>



</body>

</html>